import { createElement } from 'react';
import { InputProps } from 'antd';
import { ProFormItemProps } from '@ant-design/pro-form';
import classnames from 'classnames';
import AssembleForm from './index';
import utils from '@/utils/index';

type formProps = {
  id?: number;
  name?: string;
  label?: string;
  busType?: number; //{1:用户}
  fieldType: number; //{1:文本框，2：单选，3：多选，4：日期}
  isDefault?: number;
  isRequire?: number;
  isEnable?: number;
  multiple?: number;
  fieldOption?: string;
  describe?: string;
  createDate?: string;
  order?: number;
  max?: number;
  min?: number;
  regEx?: string;
  precision?: number; //保留几位小数
  disabled?: any;
  fieldProps?: InputProps & any;
  rule?: any;
  placeholder: string;
  dateType: string;
};

export default (props: formProps & ProFormItemProps & any) => {
// @ts-ignore
  const { isEnable, fieldType, ..._restProps } = props;

  const createFormItem = () => {
    if (!!utils.constant.FORM_TYPE_LIST[fieldType].formType) {
      return createElement(AssembleForm[utils.constant.FORM_TYPE_LIST[fieldType].formType], props);
    }
    return <div>表单类型为空，请检查系统设置！</div>;
  };

  return <div className={classnames({ hide: !isEnable })}>{createFormItem()}</div>;
};
